<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<span style="font-size:18px;">
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" type="text/css" href="purchase/css/bootstrap.min.css" />
    <link rel="stylesheet" type="text/css" href="purchase/css/commonly-used-show.css" />
    <script type="text/javascript" src="purchase/js/jquery.min.js"></script>
    <script type="text/javascript" src="purchase/js/bootstrap.js" ></script>

    <!--  缓存 -->
    <script type="text/javascript" src="purchase/js/jquery.cookie.js"></script>

    <!--时间选择 -->
    <link rel="stylesheet" type="text/css" href="purchase/css/bootstrap-datetimepicker.min.css" />
    <script type="text/javascript" src="purchase/js/bootstrap-datetimepicker.js" charset="UTF-8"></script>
    <script type="text/javascript" src="purchase/js/bootstrap-datetimepicker.zh-CN.js" charset="UTF-8"></script>



    <c:if test="${param.id != 1}">
        <title>修改出库信息</title>
    </c:if>

    <c:if test="${param.id == 1}">
        <title>添加出库信息</title>
    </c:if>



</head>

<body class="mybody">


<c:if test="${user_leve == 1}">
    <jsp:include page="theTopMenuAdmin.jsp" />
</c:if>

<c:if test="${user_leve == 2}">
    <jsp:include page="theTopMenuUser.jsp" />
</c:if>


 <div class="container-fluid">
    <div class="row">


        <div class="col-md-12">
            <div class="col-md-12">
                    <div class="panel panel-primary">
                        <div class="panel-body">
                            <div class="alert alert-success">



                                <div class="container">
                                    <c:if test="${param.id == 1}">
                                        <h3 style="text-align: center">添加出库信息</h3>
                                    </c:if>

                                    <c:if test="${param.id != 1}">
                                        <h3 style="text-align: center">修改出库信息</h3>
                                    </c:if>

        <hr style="filter: alpha(opacity=100,finishopacity=0,style=3)" width="100%" color="#6f5999" size="3" />

        <div id="reset_form" class="container">
            <div class="form-group same-line">
                <label ><b style="color: red">*&nbsp</b>商品编号：</label>
                <input type="text" id="product_id" class="form-control edit" placeholder="请输入商品编号" maxlength="20">

            </div>

            <div class="form-group same-line-left">
                <label ><b style="color: red">*&nbsp</b>商品类别：</label>
                <input type="text" id="product_type" class="form-control edit" placeholder="请输入商品类别" maxlength="10">

            </div>

            <div class="form-group same-line-left">
                <label ><b style="color: red">*&nbsp</b>单价：</label>
               <input type="text" id="unit_price" class="form-control edit" placeholder="请输入单价" maxlength="6">

            </div>

            <div class="form-group same-line">
                <label ><b style="color: red">*&nbsp</b>数量：</label>
                <input type="text" id="quantity" class="form-control edit" placeholder="请输入数量" maxlength="6">

            </div>

            <div class="form-group same-line-left">
                 <label ><b style="color: red">*&nbsp</b>供货商：</label>
                <input type="text" id="supplier" class="form-control edit" placeholder="请输入供货商" maxlength="20">

            </div>


            <div class="form-group same-line-left">
                 <label ><b style="color: red">*&nbsp</b>出库时间：</label>
                <div class="controls input-append date form_datetime">
                    <input id="delivery_time" class="form-control edit" size="16" type="text" placeholder="请选择" readonly  />
                    <span class="add-on"><i class="icon-remove"></i></span>
                    <span class="add-on"><i class="icon-th"></i></span>
                </div>
                <input class="form-control edit" type="hidden" />
            </div>

            <div class="form-group same-line">
                <label ><b style="color: red">*&nbsp</b>出库人：</label>
                <input type="text" id="delivery_man" class="form-control edit" placeholder="请输入出库人" maxlength="6">

            </div>

        </div>

        <div style="margin-top: 30px;" class="form-group text-center same-line-clear">
            <input type="button" id="mybut" value="添加" class="btn btn-primary" onclick="addDelivery()">
            <input type="reset" value="重置" class="btn btn-danger interval" onclick="reset()">
        </div>

        <div class="text-center">
            <span id="user_messge" style="font-size:10px; color: red;"></span>
        </div>

</div>



                            </div>
                        </div>
                    </div>
                </div>
        </div>



    </div>

 </div>



<script type="text/javascript">
    var userdt = JSON.parse(sessionStorage.getItem("user"));
    if (userdt.result.userName != null){
        $("#usname").text(userdt.result.userName);
    }else {
        $("#usname").text(userdt.result.userLoginName);
    }

    var postUrlua;

    //重置文本框
    function reset(){
        var addUser = document.getElementById("reset_form");
        var ipts = addUser.getElementsByTagName("input");
        for (var i = 0; i < ipts.length; i++){
            ipts[i].value = "";
        }
    }

    if ("${param.id}" !== "1"){
        window.onload = function(){
            getDelivery();
        }
        $("#mybut").val("确认修改");
        postUrlua = "${pageContext.request.contextPath}/member/updateInboundOutbound";

    }else {
        postUrlua = "${pageContext.request.contextPath}/member/addInboundOutbound";
    }


    function getDelivery(){
        var postUrl = "${pageContext.request.contextPath}/member/queryInboundOutbound";
        var str = {
            "id": "${param.id}"
        };

        $.ajax({
            type:"post",
            url:postUrl,
            headers: {
                "Content-Type":"application/json"
            },
            data:JSON.stringify(str),
            contentType: "application/json; charset=utf-8",
            dataType:"json",
            success:function(data){
                if (data.status === 0){
                    $("#user_messge").text(data.msg);
                }else {

                    $("#product_id").val(data.result.productId);
                    $("#product_type").val(data.result.productType);
                    $("#unit_price").val(data.result.unitPrice);
                    $("#quantity").val(data.result.quantity);
                    $("#supplier").val(data.result.supplier);
                    $("#delivery_time").val(data.result.deliveryTime);
                    $("#delivery_man").val(data.result.deliveryMan);

                }

            },
            error:function(xhr,state,errorThrown){
                //alert("发生网络错误，错误码为：" + xhr.status)
                location.href = "${pageContext.request.contextPath}/error";
            }
        });
    }

    function addDelivery(){
        var productId = $("#product_id").val();
        var productType = $("#product_type").val();
        var unitPrice = $("#unit_price").val();
        var quantity = $("#quantity").val();
        var supplier = $("#supplier").val();
        var deliveryTime = $("#delivery_time").val();
        var deliveryMan = $("#delivery_man").val();


        if ($.isEmptyObject(productId)){
            $("#user_messge").text("商品编号不能为空");
            return;
        } else if ($.isEmptyObject(productType)){
            $("#user_messge").text("商品类别不能为空");
            return;
        }else if ($.isEmptyObject(unitPrice)){
            $("#user_messge").text("单价不能为空");
            return;
        }else if ($.isEmptyObject(quantity)){
            $("#user_messge").text("数量不能为空");
            return;
        }else if ($.isEmptyObject(supplier)){
            $("#user_messge").text("供应商不能为空");
            return;
        }else if ($.isEmptyObject(deliveryTime)){
            $("#user_messge").text("出库时间不能为空");
            return;
        }else if ($.isEmptyObject(deliveryMan)){
            $("#user_messge").text("出库人不能为空");
            return;
        }else {
            $("#user_messge").text("");
        }


        var str = {
            "id": "${param.id}",
            "productId": productId,
            "productType": productType,
            "unitPrice": unitPrice,
            "quantity": quantity,
            "deliveryTime": deliveryTime,
            "deliveryMan": deliveryMan,
            "supplier": supplier,
            "userType": "2"
        };

        $.ajax({
            type:"post",
            url:postUrlua,
            headers: {
                "Content-Type":"application/json"
            },
            data:JSON.stringify(str),
            contentType: "application/json; charset=utf-8",
            dataType:"json",
            success:function(data){
                if (data.status === 0){
                    $("#user_messge").text(data.msg);
                }else {
                    if ("${user_leve}" === "2"){
                        reset();
                        $("#user_messge").text("添加成功");
                    }else {
                        location.href = "${pageContext.request.contextPath}/outboundQuery";
                    }

                }

            },
            error:function(xhr,state,errorThrown){
                //alert("发生网络错误，错误码为：" + xhr.status)
                location.href = "${pageContext.request.contextPath}/error";
            }
        });

    }

    //加载时间控件
    $('.form_datetime').datetimepicker({
        language: 'zh-CN', //默认语言
        format: "yyyy-mm-dd",//默认选择格式
        autoclose: true,//选中自动关闭
        todayBtn: true,//显示今日按钮
        startView: 2, //设置只显示到月份
        minView: 2

    });
</script>



</body>
</html>
</span>